$('#goto-register').on('click', function () {
    $('#register').stop().show();
})
$('#goto-login').on('click', function () {
    $('#register').stop().hide();
})

//注册功能的编写
//s给表单绑定 - 提交事件
$('#register .layui-form').on('submit', function (ev) {

    ev.preventDefault();
    var data = {
        username: $('#register input[name=username]').val(),
        password: md5($('#register input[name=password]').val())
    }
    var arr = [];
    for (var prop in data) {
        arr.push(`${prop}=${data[prop]}`);
    }
    var argstr = arr.join('&')
    // console.log(argstr);
    registerAPI(argstr, (res) => {
        console.log(res)
    })

})

//登录功能编写
$('#login .layui-form').on('submit', function (ev) {
    ev.preventDefault();
    var data = {
        username: $('#login input[name=username]').val(),
        password: md5($('#login input[name=password]').val())
    }
    var arr = [];
    for (var prop in data) {
        arr.push(`${prop}=${data[prop]}`);
    }
    var argstr = arr.join('&');
    loginAPI(argstr, (res) => {
        sessionStorage.setItem("token", res.data.token);
        window.location.href = "./index.html";
        // console.log(res)
    })

})